//
//  BCOrderViewController.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/13.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCOrderViewController.h"
#import "BCStuffThirdCollectionViewCell.h"
#import "BCOrderSecondSiderCollectionViewCell.h"
#import "BCOrderThirdCollectionViewCell.h"
#import "BCOrderFirstTableViewCell.h"
#import "BCPaidListingViewController.h"
#import "BCOrderHistoryDetailViewController.h"
#import "BCStuffInfoViewController.h"
#import "BCWaitingShopVC.h"

@interface BCOrderViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,shopCarDelegate>
//订单种类选择视图
@property (nonatomic, strong) UIView *segmentView;
//订单种类选择按钮背景
@property (nonatomic, strong) UIView *segmentItem_0_BackgroundView;
@property (nonatomic, strong) UIView *segmentItem_1_BackgroundView;
//@property (nonatomic, strong) UIView *segmentItem_2_BackgroundView;
//订单种类选择按钮
@property (nonatomic, strong) UIButton *segmentItem_0;
@property (nonatomic, strong) UIButton *segmentItem_1;
@property (nonatomic, strong) UIButton *segmentItem_2;
//三订单滚动视图
@property (nonatomic, strong) UIScrollView *mainScrollView;
//三订单背景视图
@property (nonatomic, strong) UIView *aboveScroll_0_View;
@property (nonatomic, strong) UIView *aboveScroll_1_View;
//三订单列表视图-0
@property (nonatomic, strong) UITableView *orderList_0_TableView;
//三订单列表视图-1
@property (nonatomic, strong) UICollectionView *orderList_1_CollectionView;
//三订单滚动页
@property (nonatomic, assign) NSInteger page;

@property (nonatomic,strong) CALayer *dotLayer;

@property (nonatomic,assign) CGFloat endPointX;

@property (nonatomic,assign) CGFloat endPointY;

@property (nonatomic,strong) UIBezierPath *path;

@property (nonatomic,strong) NSMutableArray *deleteArr;

@end

@implementation BCOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self p_initNavgationBar];
    [self p_initSegmentView];
    [self p_initMainScroll];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    //购物车签订协议
    self.navigationController.navigationBar.hidden = NO;
    [BCShopCarManager sharedInstance].delegate = self;
    [BCShopCarManager sharedInstance].butTitle = @"去竞价";

    if (self.rdv_tabBarController.selectedIndex != 1) {
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    }
    else {
        if (self.rdv_tabBarController.tabBarHidden) {
            [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
        }
    }
    if (!self.rdv_tabBarController.tabBarHidden) {
        [[BCShopCarManager sharedInstance] showShopWindowUp];
    }else{
        [[BCShopCarManager sharedInstance] showShopWindow];
    }
    
    if (_page) {
        [[BCShopCarManager sharedInstance] hideShopWindow];
    }
    
    NSArray *categoryArray = [BCOrderViewManager readCategoryFromOrder];
    if (categoryArray.count>0) {
        _orderList_0_TableView.hidden = NO;
        [_orderList_0_TableView reloadData];
    }
    else {
        _orderList_0_TableView.hidden = YES;
    }
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if ([scrollView isEqual:_mainScrollView]) {
        CGFloat x = scrollView.contentOffset.x;
        _page = x/scrollView.frame.size.width;
        if (_page==0) {
            self.segmentItem_0_BackgroundView.hidden = NO;
            self.segmentItem_1_BackgroundView.hidden = YES;
            if (!self.rdv_tabBarController.tabBarHidden) {
                [[BCShopCarManager sharedInstance] showShopWindowUp];
            }
            else {
                [[BCShopCarManager sharedInstance] showShopWindow];
            }
        }
        else {
            self.segmentItem_0_BackgroundView.hidden = YES;
            self.segmentItem_1_BackgroundView.hidden = NO;
            [[BCShopCarManager sharedInstance] hideShopWindow];
        }
    }
    
    if ([scrollView isEqual:_orderList_0_TableView]) {
        CGFloat sectionHeaderHeight = 40;
        CGFloat inset_bottom = 3;
        if (!self.rdv_tabBarController.tabBarHidden) {
            inset_bottom = 52.f;
        }
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, inset_bottom, 0);
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, inset_bottom, 0);
        }
    }
}

//拖动结束
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
//    CGFloat x = scrollView.contentOffset.x;
    

}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
}

#pragma mark - Private Action
- (void)rightItemAction:(UIBarButtonItem *)item {
    self.orderList_0_TableView.allowsMultipleSelectionDuringEditing = YES;
    self.orderList_0_TableView.editing = !self.orderList_0_TableView.editing;
    if (_orderList_0_TableView.editing==NO &&
        _deleteArr.count>0) {
        [_deleteArr enumerateObjectsUsingBlock:^(ORDER *model, NSUInteger idx, BOOL * _Nonnull stop) {
            [[BCShopCarManager sharedInstance] removeStuffName:model.name amount:model.count.integerValue price:model.price.doubleValue type:(BCStuffType)model.category.integerValue];
        }];
        
        [BCOrderViewManager removeOrderWithAarray:_deleteArr];
        [_deleteArr removeAllObjects];
    }
    [self.orderList_0_TableView reloadData];
}

- (void)segmentAction:(UIButton *)item {
    if (0 == item.tag) {
        self.segmentItem_0_BackgroundView.hidden = NO;
        self.segmentItem_1_BackgroundView.hidden = YES;
        self.mainScrollView.contentOffset = CGPointMake(0, 0);
        if (!self.rdv_tabBarController.tabBarHidden) {
            [[BCShopCarManager sharedInstance] showShopWindowUp];
        }
        else {
            [[BCShopCarManager sharedInstance] showShopWindow];
        }
    }
    else {
        self.segmentItem_0_BackgroundView.hidden = YES;
        self.segmentItem_1_BackgroundView.hidden = NO;
        self.mainScrollView.contentOffset = CGPointMake(self.mainScrollView.frame.size.width, 0);
        [[BCShopCarManager sharedInstance] hideShopWindow];
    }
}

- (void)goTo
{
    if (_orderList_0_TableView.editing==NO) {
        BCWaitingShopVC *orderDetailVC = [[BCWaitingShopVC alloc] init];
        [self.navigationController pushViewController:orderDetailVC animated:YES];
    }
    else {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeCustomView;
        hud.labelText = @"请完成订单编辑";
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        });
    }
}

- (void)payAction:(UIButton *)item {
    BCPaidListingViewController *orderDetailVC = [[BCPaidListingViewController alloc] init];
    [self.navigationController pushViewController:orderDetailVC animated:YES];
}

#pragma mark - View init
- (void)p_initNavgationBar {
    self.title = @"订单";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"删除"] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemAction:)];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)p_initSegmentView {
    UIFont *segmentFont = [UIFont systemFontOfSize:15];
    self.segmentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44.f)];
    self.segmentView.backgroundColor = [UIColor colorWithRed:242.f/255.f green:242.f/255.f blue:242.f/255.f alpha:1];
    [self.view addSubview:self.segmentView];
    self.segmentItem_0_BackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.segmentView.frame.size.width/2, self.segmentView.frame.size.height)];
    self.segmentItem_0_BackgroundView.backgroundColor = BangcaiGreen;
    self.segmentItem_0_BackgroundView.hidden = NO;
    self.segmentItem_0 = [UIButton buttonWithType:UIButtonTypeCustom];
    self.segmentItem_0.frame = CGRectMake(0, 0, self.segmentItem_0_BackgroundView.frame.size.width, self.segmentItem_0_BackgroundView.frame.size.height-2.5f);
    [self.segmentItem_0 setTitle:@"新订单" forState:UIControlStateNormal];
    [self.segmentItem_0.titleLabel setFont:segmentFont];
    [self.segmentItem_0 setTitleColor:[UIColor colorWithRed:0.365 green:0.365 blue:0.365 alpha:1.000] forState:UIControlStateNormal];
    [self.segmentItem_0 setBackgroundColor:[UIColor whiteColor]];
    self.segmentItem_0.tag = 0;
    [self.segmentItem_0 addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.segmentView addSubview:self.segmentItem_0_BackgroundView];
    [self.segmentView addSubview:self.segmentItem_0];
    
    self.segmentItem_1_BackgroundView = [[UIView alloc] initWithFrame:CGRectMake(self.segmentItem_0_BackgroundView.frame.size.width, 0, self.segmentView.frame.size.width/2, self.segmentView.frame.size.height)];
    self.segmentItem_1_BackgroundView.backgroundColor = BangcaiGreen;
    self.segmentItem_1_BackgroundView.hidden = YES;
    self.segmentItem_1 = [UIButton buttonWithType:UIButtonTypeCustom];
    self.segmentItem_1.frame = CGRectMake(self.segmentItem_0_BackgroundView.frame.size.width, 0, self.segmentItem_1_BackgroundView.frame.size.width, self.segmentItem_1_BackgroundView.frame.size.height-2.5f);
    [self.segmentItem_1 setTitle:@"历史订单" forState:UIControlStateNormal];
    [self.segmentItem_1.titleLabel setFont:segmentFont];
    [self.segmentItem_1 setTitleColor:[UIColor colorWithRed:0.365 green:0.365 blue:0.365 alpha:1.000] forState:UIControlStateNormal];
    [self.segmentItem_1 setBackgroundColor:[UIColor whiteColor]];
    self.segmentItem_1.tag = 1;
    [self.segmentItem_1 addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.segmentView addSubview:self.segmentItem_1_BackgroundView];
    [self.segmentView addSubview:self.segmentItem_1];
    
    UIView *middleLineView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-2.f)*0.5f, (_segmentView.frame.size.height-16.f)*0.5f, 1.f, 16.f)];
    middleLineView.backgroundColor = [UIColor lightGrayColor];
    [self.segmentView addSubview:middleLineView];
}

- (void)p_initMainScroll {
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.segmentView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-self.segmentView.frame.size.height-50.f-60.f)];
    self.mainScrollView.delegate = self;
    self.mainScrollView.backgroundColor = [UIColor whiteColor];
    self.mainScrollView.showsHorizontalScrollIndicator = NO;
    
    self.aboveScroll_0_View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mainScrollView.frame.size.width, self.mainScrollView.frame.size.height)];
    self.aboveScroll_0_View.backgroundColor = [UIColor whiteColor];
    [self.mainScrollView addSubview:self.aboveScroll_0_View];
    [self p_initMainScrollFirstView];
    
    self.aboveScroll_1_View = [[UIView alloc] initWithFrame:CGRectMake(self.mainScrollView.frame.size.width, 0, self.mainScrollView.frame.size.width, self.mainScrollView.frame.size.height)];
    self.aboveScroll_1_View.backgroundColor = [UIColor whiteColor];
    [self.mainScrollView addSubview:self.aboveScroll_1_View];
    [self p_initMainScrollSecondView];
    
    self.mainScrollView.contentSize = CGSizeMake(self.view.frame.size.width*2, self.mainScrollView.frame.size.height);
    self.mainScrollView.pagingEnabled =YES;
    [self.view addSubview:self.mainScrollView];
    
    _endPointX = (SCREEN_WIDTH/3)+(SCREEN_WIDTH/6);
    _endPointY = SCREEN_HEIGHT;
    
    if (_deleteArr == nil) {
        self.deleteArr = [NSMutableArray arrayWithCapacity:0];
    }
}

- (void)p_initMainScrollFirstView {
    self.orderList_0_TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.aboveScroll_0_View.frame.size.width, self.aboveScroll_0_View.frame.size.height) style:UITableViewStylePlain];
    self.orderList_0_TableView.delegate = self;
    self.orderList_0_TableView.dataSource = self;
    self.orderList_0_TableView.contentInset = UIEdgeInsetsMake(0, 0, self.navigationController.navigationBar.frame.size.height+20.f, 0);
    self.orderList_0_TableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.orderList_0_TableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.orderList_0_TableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    self.orderList_0_TableView.backgroundColor = [UIColor whiteColor];
    //设置contentInset属性（上左下右的值）
    CGFloat inset_bottom = 0;
//    if (!self.rdv_tabBarController.tabBarHidden) {
//        inset_bottom = 55.f;
//    }
//    else {
//        inset_bottom = 0;
//    }
    self.orderList_0_TableView.contentInset = UIEdgeInsetsMake(0, 0, inset_bottom, 0);
    [self.aboveScroll_0_View addSubview:self.orderList_0_TableView];
    
}

- (void)p_initMainScrollSecondView {
    UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc]init];
    self.orderList_1_CollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.aboveScroll_1_View.frame.size.width, self.aboveScroll_1_View.frame.size.height) collectionViewLayout:flowLayout];
    self.orderList_1_CollectionView.backgroundColor = [UIColor whiteColor];
    self.orderList_1_CollectionView.delegate = self;
    self.orderList_1_CollectionView.dataSource = self;
    //设置contentInset属性（上左下右的值）
    CGFloat inset_bottom = 0;
    if (!self.rdv_tabBarController.tabBarHidden) {
        inset_bottom = 55.f;
    }
    else {
        inset_bottom = 0;
    }
    self.orderList_1_CollectionView.contentInset = UIEdgeInsetsMake(0, 0, inset_bottom, 0);
    [self.aboveScroll_1_View addSubview:self.orderList_1_CollectionView];
}

#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSArray *categoryArray = [BCOrderViewManager readCategoryFromOrder];
    
    return categoryArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSArray *orderStuffArray = [BCOrderViewManager readStuffInCategoryFromOrderWithIndex:section];
    
    return orderStuffArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 32;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *hederView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 32)];
    UILabel *hederLable = [[UILabel alloc] initWithFrame:hederView.bounds];
    hederLable.textAlignment = NSTextAlignmentCenter;
    hederLable.textColor = [UIColor whiteColor];
    hederLable.font = [UIFont systemFontOfSize:15];
    [hederView addSubview:hederLable];
    
    NSInteger category = [BCOrderViewManager readCategoryFormOrder:section];
    switch (category) {
        case 0:
        {
            hederLable.text = @"禽蛋肉品";
            hederView.backgroundColor = ClassColor_QDRP;
        }
            break;
        case 1:
        {
            hederLable.text = @"蔬菜水果";
            hederView.backgroundColor = ClassColor_SCSG;
        }
            break;
        case 2:
        {
            hederLable.text = @"水产冻品";
            hederView.backgroundColor = ClassColor_SCDP;
        }
            break;
        case 3:
        {
            hederLable.text = @"调料其它";
            hederView.backgroundColor = ClassColor_TLQT;
        }
            break;
        case 4:
        {
            hederLable.text = @"米面粮油";
            hederView.backgroundColor = ClassColor_MMLY;
        }
            break;
        case 5:
        {
            hederLable.text = @"熟食面点";
            hederView.backgroundColor = ClassColor_SSMD;
        }
            break;
        case 6:
        {
            hederLable.text = @"酒水饮料";
            hederView.backgroundColor = ClassColor_JSYL;
        }
            break;
        case 7:
        {
            hederLable.text = @"厨房用品";
            hederView.backgroundColor = ClassColor_CFYP;
        }
            break;
            
            
        default:
            break;
    }
    
    return hederView;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *ID = @"OrderFirstCellIdentifer";
    BCOrderFirstTableViewCell *cell = [BCOrderFirstTableViewCell cellWithTableView:tableView];
    cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSArray *orderStuffArray = [BCOrderViewManager readStuffInCategoryFromOrderWithIndex:indexPath.section];
    ORDER *model = orderStuffArray[indexPath.row];
    cell.stuffNameLable.text = model.name;
    cell.priceLable.text = [NSString stringWithFormat:@"￥%@/%@",[model.price rounding:2],model.unit];
    cell.uuid = model.uuid;
    cell.countTextFeild.text = model.count.stringValue;
    cell.countTextFeild.hidden = YES;
    cell.decButton.hidden = YES;
    [cell makeAttributedString];
    
    if (tableView.editing) {
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.tintColor = BangcaiGreen;
    }
    else {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.tintColor = cell.contentView.backgroundColor;
    }

    if (orderStuffArray.count > 0) {
        cell.countTextFeild.hidden = NO;
        cell.decButton.hidden = NO;
    }
    
    __weak __typeof(&*cell)weakCell = cell;
    cell.reddot = ^() {
        CGRect parentRect = [weakCell convertRect:weakCell.addButton.frame toView:self.view];
        [self JoinCartAnimationWithRect:parentRect];
    };
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70.f;
}

//是否可以编辑  默认的时YES
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

//选择编辑的方式,按照选择的方式对表进行处理
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
    }
}

//选择你要对表进行处理的方式  默认是删除方式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}

//选中时将选中行的在self.dataArray 中的数据添加到删除数组self.deleteArr中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!tableView.isEditing) {
        BCStuffInfoViewController *stuffVC = [[BCStuffInfoViewController alloc] init];
        BCOrderFirstTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        stuffVC.stuff_uuid = cell.uuid;
        [self.navigationController pushViewController:stuffVC animated:YES];
    }
    else {
        NSArray *orderStuffArray = [BCOrderViewManager readStuffInCategoryFromOrderWithIndex:indexPath.section];
        ORDER *model = orderStuffArray[indexPath.row];
        [_deleteArr addObject:model];
    }
}
//取消选中时 将存放在self.deleteArr中的数据移除
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath  {
    NSArray *orderStuffArray = [BCOrderViewManager readStuffInCategoryFromOrderWithIndex:indexPath.section];
    ORDER *model = orderStuffArray[indexPath.row];
    [_deleteArr removeObject:model];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"ThirdCell";
    BCOrderThirdCollectionViewCell *cell = [BCOrderThirdCollectionViewCell cellWithCollectionView:collectionView];
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    return cell;
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section

{
    
    UIEdgeInsets top = {0,0,0,0};
    return top;
}

//定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(self.view.frame.size.width, 80);
}

//每个item之间的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

//每个section中不同的行之间的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

//collectionview点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"cell %@,%@ selected",@(indexPath.section),@(indexPath.row));
    BCOrderHistoryDetailViewController *nextController = [[BCOrderHistoryDetailViewController alloc] init];
    [self.navigationController pushViewController:nextController animated:YES];
}

- (void)pushWithData:(NSDictionary *)datadic{
    BCStuffInfoViewController *stuffVC = [[BCStuffInfoViewController alloc] init];
    stuffVC.popOrPush = YES;
    [self.navigationController pushViewController:stuffVC animated:YES];
    
}

#pragma mark -加入购物车动画
-(void) JoinCartAnimationWithRect:(CGRect)rect
{
    
    CGFloat startX = rect.origin.x;
    CGFloat startY = rect.origin.y;
    
    _path= [UIBezierPath bezierPath];
    [_path moveToPoint:CGPointMake(startX, startY)];
    //三点曲线
    [_path addCurveToPoint:CGPointMake(_endPointX, _endPointY)
             controlPoint1:CGPointMake(startX, startY)
             controlPoint2:CGPointMake(startX - 180, startY - 200)];
    
    _dotLayer = [CALayer layer];
    _dotLayer.backgroundColor = [UIColor redColor].CGColor;
    _dotLayer.frame = CGRectMake(0, 0, 15, 15);
    _dotLayer.cornerRadius = (15 + 15) /4;
    [self.view.layer addSublayer:_dotLayer];
    [self groupAnimation];
    
}
#pragma mark - 组合动画
-(void)groupAnimation
{
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.path = _path.CGPath;
    animation.rotationMode = kCAAnimationRotateAuto;
    
    CABasicAnimation *alphaAnimation = [CABasicAnimation animationWithKeyPath:@"alpha"];
    alphaAnimation.duration = RedAnimationDuring;
    alphaAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    alphaAnimation.toValue = [NSNumber numberWithFloat:0.1];
    alphaAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    
    CAAnimationGroup *groups = [CAAnimationGroup animation];
    groups.animations = @[animation,alphaAnimation];
    groups.duration = RedAnimationDuring+0.3f;
    groups.removedOnCompletion = NO;
    groups.fillMode = kCAFillModeForwards;
    groups.delegate = self;
    [groups setValue:@"groupsAnimation" forKey:@"animationName"];
    [_dotLayer addAnimation:groups forKey:nil];
    
    [self performSelector:@selector(removeFromLayer:) withObject:_dotLayer afterDelay:RedAnimationDuring+0.3f];
    
}
- (void)removeFromLayer:(CALayer *)layerAnimation{
    
    [layerAnimation removeFromSuperlayer];
}

@end
